package com.newhopegroup.webcommons.jsJsonCrossCall;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

        import javax.servlet.http.HttpServletResponse;

/**
 * Created by liusen on 15-7-14.
 */
@Controller
public class OptionsController {

    private static final Logger logger = LoggerFactory.getLogger(JsonCrossCallForJSInterceptor.class);

    @RequestMapping(method = RequestMethod.OPTIONS)
    public void OptionsHandler(HttpServletResponse response) {
        logger.debug("OptionsController preHandle start");

        response.setHeader("Access-Control-Allow-Headers", "origin, content-type, accept, x-requested-with");
//            response.setHeader("Access-Control-Max-Age", "60"); // seconds to cache preflight request --> less OPTIONS traffic
        response.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
        response.setHeader("Access-Control-Allow-Origin", "*");

        logger.debug("OptionsController preHandle over");
    }
}
